package com.wwu.system.controller;

import com.wwu.common.constant.CommConst;
import com.wwu.common.enums.MenuBtnEnum;
import com.wwu.common.web.ResultObj;
import com.wwu.system.common.aspect.Log;
import com.wwu.system.entity.SysUser;
import com.wwu.system.service.ISysUserRoleService;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 系统用户角色前端控制器
 * @author 一蓑烟雨
 * @date 2021-10-26
 * @version 1.0.0
 */
@Api(tags = "系统用户角色控制器(SysUserRoleController)")
@ApiSort(5)
@Controller
@RequestMapping("/system/sysUserRole")
public class SysUserRoleController {
    @Resource
    private ISysUserRoleService sysUserRoleService;

    @Log(menuName = "用户角色管理",menuBtnEnum = MenuBtnEnum.SHOW)
    @ApiOperation(value = "根据用户id查询用户的角色树")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParam(name = "userId", value = "用户Id")
    @GetMapping("/userRoleTree")
    @ResponseBody
    public ResultObj userRoleTree(String userId){
        return sysUserRoleService.userRoleTree(userId);
    }

    @Log(menuName = "用户角色管理",menuBtnEnum = MenuBtnEnum.EDIT)
    @ApiOperation(value = "更新用户角色信息")
    @ApiOperationSupport(order = 2)
    @PutMapping("/updateUserRoleByUserId")
    @ResponseBody
    public  ResultObj updateUserRoleByUserId(@RequestBody SysUser sysUser){
        sysUserRoleService.updateUserRoleByUserId(sysUser);
        return ResultObj.success("用户角色更新成功");
    }

    @Log(menuName = "用户角色管理",menuBtnEnum = MenuBtnEnum.DEL)
    @ApiOperation(value = "删除用户角色信息")
    @ApiOperationSupport(order = 3)
    @DeleteMapping("/deleteUserRoleByUserId/{userIds}")
    @ResponseBody
    public ResultObj deleteUserRoleByUserId(@ApiParam(name = "userIds", value = "用户id集合，以逗号分隔", required = true)
                                                @PathVariable String userIds){
        sysUserRoleService.deleteUserRoleByUserId(Arrays.asList(userIds.split(CommConst.SPLIT_COMMA)));
        return ResultObj.success("用户角色删除成功");
    }
}